import { UserView } from '@/entities/user-view.entity';
import { User } from '@/entities/user.entity';
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';

@Injectable()
export class UserService {
  @InjectRepository(User)
  private userRepository: Repository<User>;
  @InjectRepository(UserView)
  private userViewRepository: Repository<UserView>;

  async findByUserName(username: string): Promise<User> {
    return await this.userRepository.findOneBy({ username });
  }

  async findOne(id: number): Promise<User> {
    return await this.userRepository.findOneBy({ id });
  }

  async findOneFromView(id: number): Promise<UserView> {
    return await this.userViewRepository.findOneBy({ id });
  }
}
